home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar
/
1995
/
SEP
/
RH9509
/
STPWATCH
/
VTIMERDV.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1995-08-15
|
2KB
|
76 lines
unit VTimerDv; { Access the Windows Virtual Timer Device (VTD) }
interface
function VTD_GetTime: double;
implementation
const
{ Conversion factor must be a typed constant, since Delphi's built-in
assembler cannot reference floating point constants by name. }
SecondsPerTick: double = 0.836E-6; { Timer rate is 1.196 MHz }
var
VTDSegment: word;
VTDOffset: word;
VTDTicks: comp; { 64-bit signed integer }
procedure VTD_GetEntryPoint;
begin
{ Call Windows to get address of VTD entry point. }
asm
mov ax,$1684 { Code to ask for an API's entry point }
mov bx,$05 { Code for Virtual Timer Device (VTD) }
xor di,di { Clear ES:DI }
mov es,di
int $2F { Call Windows }
mov VTDSegment,es { Save results }
mov VTDOffset,di
end;
end;
function VTD_GetTime: double;
begin
{ Call VTD to get the elapsed time in seconds since Windows was started. }
asm
mov dx,VTDSegment { Load the entry point }
mov ax,VTDOffset
push cs { Push our call-back address }
mov bx, offset @RetSpot
push bx
push dx { Push the entry point }
push ax
mov ax,$100 { Load ID for function VTD_Get_Real_Time }
retf { Call the VTD }
@RetSpot:
nop { Just a place to come home to }
end;
{ The 64-bit tick count is returned in the 32-bit registers EAX and EDX.
Since Delphi's built-in assembler does not support 32-bit registers,
use machine code to transfer these registers into the lower and upper
parts of a 64-bit integer. Then push that 64-bit integer onto the
coprocessor stack. }
inline
(
$66/ { Toggle operand size }
$89/$06/>VTDTicks/ { mov VTDTicks,eax }
$66/ { Toggle operand size }
$89/$16/>VTDTicks+4/ { mov VTDTicks+4,edx }
$DF/$2E/>VTDTicks { fild[64] VTDTicks }
);
{ Convert from ticks to seconds. }
asm
fmul SecondsPerTick { Multiply by the conversion factor }
fstp @result { Store in @result and pop the stack }
end;
end;
initialization
VTD_GetEntryPoint;
end.